package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.system.service.IPersonnelUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PersonnelClockIn;
import com.ruoyi.system.service.IPersonnelClockInService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * 打卡记录Controller
 *
 * @author ruoyi
 * @date 2023-09-05
 */
@Controller
@RequestMapping("/system/in")
public class PersonnelClockInController extends BaseController
{
    private String prefix = "system/in";

    @Resource
    private IPersonnelClockInService personnelClockInService;

    @Resource
    private IPersonnelUserService personnelUserService;

    @RequiresPermissions("system:in:view")
    @GetMapping()
    public String in()
    {


        return prefix + "/in";
    }

    /**
     * 查询打卡记录列表
     */
    @RequiresPermissions("system:in:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PersonnelClockIn personnelClockIn)
    {
        startPage();
        System.out.println(personnelClockIn.getDoorTime());
        List<PersonnelClockIn> list = personnelClockInService.selectPersonnelClockInList(personnelClockIn);
        return getDataTable(list);
    }

    /**
     * 导出打卡记录列表
     */
    @RequiresPermissions("system:in:export")
    @Log(title = "打卡记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PersonnelClockIn personnelClockIn)
    {
        List<PersonnelClockIn> list = personnelClockInService.selectPersonnelClockInList(personnelClockIn);
        ExcelUtil<PersonnelClockIn> util = new ExcelUtil<PersonnelClockIn>(PersonnelClockIn.class);
        return util.exportExcel(list, "打卡记录数据");
    }

    /**
     * 新增打卡记录
     */
    @GetMapping("/add")
    public String add(ModelMap modelMap)
    {
        modelMap.put("personnelUserList",personnelUserService.list());
        return prefix + "/add";
    }

    /**
     * 新增保存打卡记录
     */
    @RequiresPermissions("system:in:add")
    @Log(title = "打卡记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PersonnelClockIn personnelClockIn)
    {
        return toAjax(personnelClockInService.insertPersonnelClockIn(personnelClockIn));
    }

    /**
     * 修改打卡记录
     */
    @RequiresPermissions("system:in:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PersonnelClockIn personnelClockIn = personnelClockInService.selectPersonnelClockInById(id);
        mmap.put("personnelClockIn", personnelClockIn);
        mmap.put("personnelUserList",personnelUserService.list());
        return prefix + "/edit";
    }

    /**
     * 修改保存打卡记录
     */
    @RequiresPermissions("system:in:edit")
    @Log(title = "打卡记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PersonnelClockIn personnelClockIn)
    {
        return toAjax(personnelClockInService.updatePersonnelClockIn(personnelClockIn));
    }

    /**
     * 删除打卡记录
     */
    @RequiresPermissions("system:in:remove")
    @Log(title = "打卡记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(personnelClockInService.deletePersonnelClockInByIds(ids));
    }
}
